package com.xn.app.muying.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.xn.app.muying.R;
import com.xn.app.muying.fragment.KePuManFragment;
import com.xn.app.muying.fragment.KePuWomanFragment;
import com.xn.app.muying.util.BaseActivity;
import com.zhuge.analysis.stat.ZhugeSDK;

/**
 * 孕前检查
 * Created by Administrator on 2016/10/13.
 */
public class KePuActivity extends BaseActivity implements View.OnClickListener {

    private TextView kepu_womam;
    private TextView kepu_mam;
    private Fragment mContent;
    private KePuWomanFragment kepuwomanfragment;
    private KePuManFragment kepumanfragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kepu);
        kepu_womam = (TextView) findViewById(R.id.kepu_activity_woman_tv);
        kepu_mam = (TextView) findViewById(R.id.kepu_activity_man_tv);
        ImageView back = (ImageView) findViewById(R.id.kepu_activity_back);
        kepu_womam.setOnClickListener(this);
        kepu_mam.setOnClickListener(this);
        back.setOnClickListener(this);
        kepuwomanfragment = new KePuWomanFragment();
        kepumanfragment = new KePuManFragment();
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        ft.add(R.id.kepu_activity_ll, kepuwomanfragment).commit();
        mContent = kepuwomanfragment;

    }
    public void switchContent(Fragment to) {
        if (mContent != to) {
            FragmentManager fm = getSupportFragmentManager();
            FragmentTransaction transaction = fm.beginTransaction();
            if (!to.isAdded()) {    // 先判断是否被add过
                transaction.hide(mContent).add(R.id.kepu_activity_ll, to).commit(); // 隐藏当前的fragment，add下一个到Activity中
                mContent = to;
            } else {
                transaction.hide(mContent).show(to).commit(); // 隐藏当前的fragment，显示下一个
                mContent = to;
            }
        }
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.kepu_activity_woman_tv:
                switchContent(kepuwomanfragment);
                kepu_womam.setBackgroundResource(R.drawable.button_red_kepu1);
                kepu_mam.setBackgroundResource(R.drawable.button_white_kepu2);
                kepu_womam.setText("女性检查项目");
                kepu_womam.setTextColor(getResources().getColor(R.color.white));
                kepu_mam.setText("男性检查项目");
                kepu_mam.setTextColor(getResources().getColor(R.color.sys_fen));
                break;
            case R.id.kepu_activity_man_tv:
                switchContent(kepumanfragment);
                kepu_mam.setBackgroundResource(R.drawable.button_red_kepu2);
                kepu_womam.setBackgroundResource(R.drawable.button_white_kepu1);
                kepu_womam.setText("女性检查项目");
                kepu_womam.setTextColor(getResources().getColor(R.color.sys_fen));
                kepu_mam.setText("男性检查项目");
                kepu_mam.setTextColor(getResources().getColor(R.color.white));
                break;
            case R.id.kepu_activity_back:
                finish();
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
}
